package com.readbook.service;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.readbook.dao.PermissionDao;
import com.readbook.util.HttpPostUrl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

@Service
public class PermissonService {
    @Autowired
    private PermissionDao permissionDao;


    /**
     * @author 牟明艳
     * @comments 保存用户权限
     * @time 2019年10月16日14:25:39
     */
    public Map<String,Object> add_Userpermission(Map<String,Object>gmap)
    {
        Map<String,Object>remap=new HashMap<String,Object>();
        //查询该账号权限是否重复添加
        List<Map<String,Object>>list1=new ArrayList<>();
        list1=permissionDao.getUserpermissionCf(gmap);
        if(list1.size()>0){
            remap.put("msg","该账号已经添加了该权限，不能重复添加!");
            remap.put("result",false);
            return remap;
        }
        int k=permissionDao.add_Userpermission(gmap);
        if(k<=0){
            remap.put("msg","保存失败!");
            remap.put("result",false);
        }else{
            remap.put("msg","保存成功!");
            remap.put("result",true);
        }
        return remap;
    }

    /**
     * @author 牟明艳
     * @comments 修改用户权限
     * @time 2019年10月16日14:56:14
     */
    public Map<String,Object> edit_Userpermission(Map<String,Object>gmap)
    {
        Map<String,Object>remap=new HashMap<String,Object>();
        //先删除账号权限
        permissionDao.del_Userpermission(gmap);
        int k=permissionDao.add_Userpermission(gmap);
        if(k<=0){
            remap.put("msg","保存失败!");
            remap.put("result",false);
        }else{
            remap.put("msg","保存成功!");
            remap.put("result",true);
        }
        return remap;
    }

    /**
     * @author 牟明艳
     * @comments 删除用户权限
     * @time 2019年10月16日15:19:48
     */
    public Map<String,Object> removeUserpermission(Map<String,Object>gmap)
    {
        Map<String,Object>remap=new HashMap<String,Object>();
        int k=permissionDao.del_Userpermission(gmap);
        if(k<=0){
            remap.put("msg","删除失败!");
            remap.put("result",false);
        }else{
            remap.put("msg","删除成功!");
            remap.put("result",true);
        }
        return remap;
    }


    public List<Map<String,Object>>search_Userpermission(Map<String,Object>gmap)
    {
        List<Map<String,Object>>list1=permissionDao.search_Userpermission(gmap);
        return list1;
    }

}
